<html>
<script>
function log(s)
{
    var logDiv = document.getElementById("log");
    logDiv.appendChild(document.createTextNode(s));
    logDiv.appendChild(document.createElement("br"));
}

function test()
{
    if (window.testRunner) {
        testRunner.dumpAsText();
        // This test outputs a RangeError to console due to hitting the maximum
        // call stack size. The exact error message and number of error messages
        // depend on the testing environment, so suppress console messages.
        testRunner.setDumpConsoleMessages(false);
    }
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        lastReadyStateObserved = xhr.readyState;
        if (xhr.readyState == 4) {
            try {
                xhr.open("GET", "recurse.html", false);
                xhr.send(null);
            } catch(e) {
                log("FAIL: An event listener should not throw an exception.");
            }
        }
    };
    xhr.open("GET", "recurse.html", false);
    try { xhr.send(null); } catch (e) {}
    log("PASS");
}
</script>
<body onload="test()">
This tests that having infinite recursion in XMLHttpRequest event handler does not crash.
<br>
<div id="log"></div>
</body>
</html>
